package com.yu.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.crm.domain.pojo.CrmAreaManage;
import com.yu.crm.domain.pojo.CrmDevice;
import com.yu.crm.domain.pojo.District;
import com.yu.crm.domain.pojo.Station;
import com.yu.crm.service.impl.DistrictService;
import com.yu.crm.service.impl.StationService;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zds
 * @since 2021-03-12
 */
@Api(tags = "站点管理")
@RestController
@RequestMapping("/station")
public class StationController {

    @Autowired
    private StationService stationService;

    @Autowired
    private DistrictService districtService;

    @ApiOperation("获取区域名")
    @GetMapping("/getDisdictName")
    public List<String> getDisdictName(){
        List<District> districtList = districtService.list();
        return districtList.stream().map(District::getDname).collect(Collectors.toList());
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/remove-batch-by-id")
    public void removeBatchById(@RequestParam("ids") String ids){
        stationService.deleteByIds(ids);
    }

    @ApiOperation("根据id删除车站")
    @DeleteMapping("/remove-by-id/{id}")
    public void removeById(@PathVariable Long id){
        stationService.deleteById(id);
    }

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/saveOrUpdate")
    public void save(@RequestBody Station station){
        stationService.saveOrUpdate(station);
    }

    /**
     * 通过站点主键查询站点详情
     * @param id 站点主键
     * @return
     */
    @ApiOperation(value = "通过站点主键查询站点详情")
    @GetMapping(value = "/info-by-id")
    public Station infoById(@RequestParam("id") Long id){
        ValidatorHelpers.notEmpty(id, "站点编号不能为空");
        return stationService.infoById(id);
    }

//    @ApiOperation("通过车站名查询")
//    @GetMapping("/selectList")
//    public IPage<Station> selectList(Page<Station> page, String stationName){
//        QueryWrapper<Station> queryWrapper = new QueryWrapper<Station>();
//        queryWrapper.eq("is_deleted",0);
//        queryWrapper.eq("station_name", stationName);
//        return stationService.page(page, queryWrapper);
//    }

//    @ApiOperation("通过车站名查询2")
//    @GetMapping("/selectList2")
//    public List<Station> selectList(String stationName){
//        QueryWrapper<Station> queryWrapper = new QueryWrapper<Station>();
//        queryWrapper.eq("is_deleted",0);
//        queryWrapper.eq("station_name", stationName);
//        return stationService.list(queryWrapper);
//    }

    @ApiOperation(value = "查询列表")
    @GetMapping(value = "/page")
    public IPage<Station> getPage(Page<Station> page,
                                  @RequestParam(required = false) String stationName,
                                  @RequestParam(required = false) String condition) {
        return stationService.getPage(page, stationName,  condition);
    }

    @ApiOperation(value = "查询列表导出用")
    @GetMapping(value = "/pageList")
    public List<Station> getPageList( @RequestParam(required = false) String stationName,
                                  @RequestParam(required = false) String condition) {
        return stationService.getPageList(stationName,  condition);
    }

    @ApiOperation(value = "查询车站名")
    @GetMapping(value = "/stationName")
    public List<String> getStationName(){
        return stationService.getStationName();
    }

}

